﻿using AutoMapper;
using EFEntity;
using ISerives;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serives
{
    public class config_major_kindServices : Iconfig_major_kindServices
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;
        public config_major_kindServices(MyDbContext myDbContext, IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> Add(config_major_kind s)
        {
            myDbContext.ZWFL.Add(s);
            int num = await myDbContext.SaveChangesAsync();
            return num;
        }

        public async  Task<int> Delete(int id)
        {
            config_major_kind ef = new config_major_kind()
            {
                mfk_id = id
            };
            myDbContext.ZWFL.Attach(ef);
            myDbContext.ZWFL.Remove(ef);
            int num = await myDbContext.SaveChangesAsync();
            return num;
        }

        public async Task<List<Mconfig_major_kind>> Select()
        {
            List<Mconfig_major_kind> list1 = new List<Mconfig_major_kind>();
            await Task.Run(() =>
            {
                List<config_major_kind> list = myDbContext.ZWFL.ToList();
                list1 = mapper.Map<List<Mconfig_major_kind>>(list);

            });
            return list1;
        }
    }
}
